package com.ts.enterprise.module.user.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ts.enterprise.common.interceptor.AuthInterceptor;
import com.ts.enterprise.common.query.LoginUser;
import com.ts.enterprise.common.service.CommonService;
import com.ts.enterprise.module.user.entity.Worker;
import com.ts.enterprise.module.user.mapper.WorkerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author dean
 * @since 2021-10-18
 */
@Service
public class WorkerService extends ServiceImpl<WorkerMapper, Worker>{

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Autowired
    private CommonService commonService;

    @Autowired
    private LoginService loginService;

    public Object getDetailById() {
        LoginUser loginUser = AuthInterceptor.user.get();
        Worker byId = super.getById(loginUser.getId());
        return byId;
    }

    public Worker getByMobile(String mobile) {
        List<Worker> list = super.list(new LambdaQueryWrapper<Worker>().eq(Worker::getMobile, mobile));
        if (CollectionUtils.isNotEmpty(list)){
            return list.get(0);
        }
        return null;
    }
}
